package de.velvettear.bruteforce.util;

import javax.swing.JTextArea;

public class Log {

	private static StringBuffer logBuffer; 
	private static JTextArea log;	
	
	public static void activate(JTextArea ta_log) {
		log = ta_log;
	}
	
	public static void trace(String msg) {
		if (logBuffer == null) {
			logBuffer = new StringBuffer();
		}
		
		logBuffer.append(Timestamp.getFormatted() + " " + msg);
		logBuffer.append(System.getProperty("line.separator"));
		
		if (log != null) {
			log.append(Timestamp.getFormatted() + msg);
			log.append(System.getProperty("line.separator"));
		}
	}
	
	public static void error(Exception e) {
		if (e.getMessage() != null) {
			trace(e.getMessage());
		}
		e.printStackTrace();
	}
			
}
